import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
var _excluded = ["modalVisible", "hideModal", "confirmLoading", "sideBar", "title"];

var _dec, _class;

import React, { PureComponent } from 'react';
import { Modal } from 'antd';
import { Bind } from 'lodash-decorators';
import SideBar from "./SideBar";
var ModalForm = (_dec = Bind(), (_class = /*#__PURE__*/function (_PureComponent) {
  _inherits(ModalForm, _PureComponent);

  var _super = _createSuper(ModalForm);

  function ModalForm() {
    _classCallCheck(this, ModalForm);

    return _super.apply(this, arguments);
  }

  _createClass(ModalForm, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      var onRef = this.props.onRef;
      if (onRef) onRef(this);
    }
  }, {
    key: "resetForm",
    value: function resetForm() {
      var form = this.props.form;
      form.resetFields();
    }
  }, {
    key: "onOk",
    value: function onOk() {
      var _this$props = this.props,
          form = _this$props.form,
          handleAdd = _this$props.handleAdd;
      form.validateFields(function (err, fieldsValue) {
        if (err) return;
        handleAdd(fieldsValue);
      });
    }
  }, {
    key: "renderForm",
    value: function renderForm() {
      return null;
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
          modalVisible = _this$props2.modalVisible,
          hideModal = _this$props2.hideModal,
          _this$props2$confirmL = _this$props2.confirmLoading,
          confirmLoading = _this$props2$confirmL === void 0 ? false : _this$props2$confirmL,
          _this$props2$sideBar = _this$props2.sideBar,
          sideBar = _this$props2$sideBar === void 0 ? false : _this$props2$sideBar,
          title = _this$props2.title,
          otherProps = _objectWithoutProperties(_this$props2, _excluded);

      var Component = sideBar ? SideBar : Modal;
      return /*#__PURE__*/React.createElement(Component, Object.assign({
        title: title,
        visible: modalVisible,
        onCancel: hideModal,
        onOk: this.onOk,
        confirmLoading: confirmLoading
      }, otherProps), this.renderForm());
    }
  }]);

  return ModalForm;
}(PureComponent), (_applyDecoratedDescriptor(_class.prototype, "onOk", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "onOk"), _class.prototype)), _class));
export { ModalForm as default };